/****************************************************
          File Name:8-6.cpp
          Author: Abby Cin
          Mail: abbytsing@gmail.com
          Created Time: Sat 20 Dec 2014 08:08:44 PM CST
*****************************************************/

#include<iostream>
#include<cstring>
using namespace std;

//template<class T> T maxn(const T a[], int n)
// general template shall not contents 'const'. if so, clang++ can't compile
template<class T> T maxn(T a[], int n)
{
    T tmp = a[0];
    for(int i=0; i<n; i++)
    {
        if(tmp < a[i])
            tmp = a[i];
    }
    return tmp;
}


template<> char *maxn(char *a[], int n)
//char *maxn(char *a[], int n)
{
    int len = strlen(a[0]);
    char *res;
    for(int i = 0; i < n; i++)
    {
        if(len < strlen(a[i]))
        {
            len = strlen(a[i]);
            res = a[i];
        }
    }

    cout << "res = " << res << endl;
    return res;
}

int main()
{
    // c++11
    int a[] {1,2,3,4,5,6};
    double b[] {7,8,9,11};

    cout << "Tesing int\n";
    cout << maxn(a, 6) << endl;
    cout << "Testing double\n";
    cout << maxn(b, 4) << endl;

    const char *c[]=
    {
        "abby cin",
        "angel criss",
        "sloger",
        "porker lee",
        "sepller green"
    };

    cout << "Tesing char *c[]\n";
    cout << maxn(c, 5) << endl;

    return 0;
}
